/**
* 缓冲函数
* @param { Number } curPosition 当前滚动位置
* @param { Number } destination 目标位置
* @param { Number } rate 缓动率
* @param { Function } callback 缓动结束回调函数 参数是当前位置
*/
const easeout = (curPosition, destination = 0, rate = 2, callback) => {
  if (curPosition === destination || typeof destination !== 'number') {
    return false
  }
  requestAnimationFrame = requestAnimationFrame || (fn => setTimeout(fn, 17))
  const step = () => {
    const distance = destination - curPosition
    curPosition = curPosition + distance / rate
    if (Math.abs(distance) < 1) {
      callback(destination)
    } else {
      callback(curPosition)
      requestAnimationFrame(step)
    }
  }
  step()
}
export default easeout

